package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.feign.product.SkuDetailFeignClient;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import com.atguigu.gmall.feign.item.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.math.BigDecimal;

@Controller
public class ItemController {

    @Autowired
    ItemFeignClient itemFeignClient;

    @Autowired
    SkuDetailFeignClient skuDetailFeignClient;

    /**
     * 商品详情页
     * @param skuId
     * @param model
     * @return
     */
    @GetMapping("{skuId}.html")
    public String index(@PathVariable("skuId") Long skuId , Model model){

        SkuDetailVo skuDetailVo = itemFeignClient.getItemDetail(skuId).getData();
        //详情数据
        //1.分类视图(category1Id , category1Name,category2Id , category2Name,category3Id , category3Name)
        model.addAttribute("categoryView",skuDetailVo.getCategoryView());
        //2.sku信息{基本信息，图片信息}
        model.addAttribute("skuInfo",skuDetailVo.getSkuInfo());
        //3.实时价格
        BigDecimal data = skuDetailFeignClient.getPrice(skuId).getData();
        model.addAttribute("price",data);
        //4.所有销售属性集合
        model.addAttribute("spuSaleAttrList",skuDetailVo.getSpuSaleAttrList());
        //5.valuesJson
        model.addAttribute("valuesJson",skuDetailVo.getValuesJson());
        //6.平台属性
        return "item/index";
    }
}
